//
//#include "../../engine.h"
//
//#include "../../User.h"
//#include "../../Data.h"
//
//#include "../../NResource/Static.h"
//
//#include "../../NLogic/Item.h"
//#include "../../NLogic/Bag.h"
//#include "../../NLogic/Space.h"
//
//#include "matching.h"
//
//namespace ProjectZ { namespace NCommand { namespace NMatching {
//
//
//void CS_DUNGEON_CARD_REWARD::OnExecute(User * pUser, ::Network::Packet * pPacket)
//{
//	NLogic::Space * pSpace = pUser->GetSpace();
//	if (NULL == pSpace)
//	{
//		DEBUGLOG("WARNING: CN_DUNGEON_CARD_REWARD GID %d, pSpace is NULL", pUser->GetUserSeq());
//		return;
//	}
//
//	if (pSpace->GetData()._spaceType != NLogic::Space::SpaceType::SINGLE_DUNGEION &&
//			pSpace->GetData()._spaceType != NLogic::Space::SpaceType::PARTY_DUNGEION )
//	{
//		DEBUGLOG("CS_DUNGEON_CARD_REWARD space is not single or party dungeion");
//		return;
//	}
//
//	PREPARE_PACKET;
//
//	int gid = 0;
//	int opencard = 0;
//
//	pPacket->ParseMsg("%d%d", &gid, &opencard);
//
//	if( opencard < 0 || opencard > 3)
//	{
//		DEBUGLOG("WARNING: CN_DUNGEON_CARD_REWARD invalid opencard number %d", opencard);
//		return;
//	}
//
//	//
//	int Reward = 0;
//	if( pSpace->GetCardReward()[opencard]->gid == -1 && IsOpen(pSpace, opencard, pUser->GetUserSeq()) == false)
//	{
//		Reward = ACK_OK;
//
//		pSpace->GetCardReward()[opencard]->gid = pUser->GetUserSeq();
//		//strncpy(pSpace->GetCardReward()[opencard]->userid, pUser->nickname, strlen(pUser->nickname));
//		//strncpy(pSpace->GetCardReward()[opencard]->userid, pUser->GetUserInfo().nickname.c_str(), pUser->GetUserInfo().nickname.length());
//
//		NLogic::Item::Data clsData;
//		NResource::Static::InstancePtr()->GetDungeonReward()->DungeonReward(pUser, clsData, opencard);
//		NLogic::Bag * pBag = pUser->GetBag(static_cast<INVEN_BAG_TYPE>(clsData.bag_type));
//		if (pBag == NULL)
//		{
//			SendPacket(pUser, ACK_UNKNOWN_ERROR, opencard);
//			return;
//		}
//
//		NLogic::Item * pItem = pBag->AddItemWithData(clsData);
//		if (NULL == pItem)
//		{
//			// TODO
//			SendPacket(pUser, ACK_INVEN_BAG_FULL, opencard);
//			return;
//		}
//
//		pSpace->GetCardReward()[opencard]->item_seq = pItem->GetItemSeq();
//		pSpace->GetCardReward()[opencard]->bag_type = clsData.bag_type;
//	}
//
//	SendPacket(pUser, Reward, opencard);
//}
//
//bool CS_DUNGEON_CARD_REWARD::IsOpen(NLogic::Space * pSpace, int opencard, int gid)
//{
//	bool ret = false;
//
//	if (opencard != 3)
//	{
//		for (int i = 0; i < 3; i++)
//		{
//			if (pSpace->GetCardReward()[i]->gid == gid)
//			{
//				ret = true;
//				break;
//			}
//		}
//	}
//
//	return ret;
//}
//
//void CS_DUNGEON_CARD_REWARD::SendPacket(User * pUser, int res, int openCard)
//{
//	::Network::Packet * pNoti = ::Network::GETPACKETPOOL()->SEND_NEW();
//
//	pNoti->MsgCat("%2d", res);
//	pNoti->MsgCat("%4d", pUser->GetSpace()->GetCardReward()[openCard]->gid);
//	pNoti->MsgCat("%8d", pUser->GetSpace()->GetCardReward()[openCard]->item_seq);
//	pNoti->MsgCat("%c", pUser->GetSpace()->GetCardReward()[openCard]->bag_type);
//	pNoti->MsgCat("%4d", openCard);
//	pNoti->MakePacket(CMD_SN_DUNGEON_CARD_REWARD);
//	pUser->GetSpace()->SendAll(pNoti);
//}
//
//} /*NBattle*/ } /*NCommand*/ } /*ProjectZ*/
